package com.leruan.aasimp.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Expression;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.leruan.aasimp.dao.CompanyInfoDao;
import com.leruan.aasimp.entity.CarCompanyInfo;

public class CompanyInfoDaoImpl extends HibernateDaoSupport implements CompanyInfoDao{

	public void addCompany(CarCompanyInfo companyInfo) {
		Session session = this.getSession();
		session.save(companyInfo);
	}

	public CarCompanyInfo getCompanyByID(String userid) {
		Session session = this.getSession();
		Criteria cri = session.createCriteria(CarCompanyInfo.class);
		Criterion  c1 = Expression.eq("userId", userid);
		Criterion  c2 = Expression.eq("status", "1");
		cri.add(c1);
		cri.add(c2);
		CarCompanyInfo result = (CarCompanyInfo) cri.uniqueResult();
		return result;
	}

	public void updateCompany(CarCompanyInfo companyInfo) {
		Session session = this.getSession();
		session.update(companyInfo);
	}

	@SuppressWarnings("unchecked")
	public List<CarCompanyInfo> getCompanys() {
		Session session = this.getSession();
		Criteria cri = session.createCriteria(CarCompanyInfo.class);
		Criterion  c1 = Expression.eq("type", "1");
		Criterion  c2 = Expression.eq("status", "1");
		cri.add(c1);
		cri.add(c2);
		List<CarCompanyInfo> list = cri.list();
		return list;
	}

	@SuppressWarnings("unchecked")
	public List<CarCompanyInfo> getMrCompanys() {
		Session session = this.getSession();
		String hql = "from  CarCompanyInfo c , Eauser t where t.userId=c.userId and t.userType='7' and c.type='1' and c.status='1'";
		List<CarCompanyInfo> list = session.createQuery(hql).list();
		return list;
	}

}
